package com.framework.jqgrid;

import com.github.pagehelper.PageInfo;

import java.util.Arrays;

/**
 * 向前台统一返回分页相关
 * Created by Saber on 2016/5/24.
 */
public class Page {
    private Integer prePage = 1;       //上一页
    private Integer currentPage;       //上一页
    private Integer nextPage;          //下一页
    private Integer totalPage;         //总页数       5
    private boolean isFirstPage;        //是否第一页    true
    private boolean isLastPage;         //是否最后一页  true
    private boolean hasPrePage;         //是否有上一页  true
    private boolean hasNextPage;        //是否有下一页  true
    private int[] navigatepageNums;     //页码 [1,2,3,4,5]



    public Page(Integer pre_page, Integer current_page, Integer next_page, Integer total_page) {
        this.prePage = pre_page;
        this.currentPage = current_page;
        this.nextPage = next_page;
        this.totalPage = total_page;
    }

    /**
     *
     * @param pageInfo      pageInfo对象
     * @param pageNo        当前页（前天传过来的值）
     */
    public Page(PageInfo pageInfo,int pageNo) {
        this.prePage = pageInfo.getPrePage();
        this.currentPage = pageNo;
        this.nextPage = pageInfo.getNextPage();
        this.totalPage = pageInfo.getPages();
        this.isFirstPage = pageInfo.isIsFirstPage();
        this.isLastPage = pageInfo.isIsLastPage();
        this.hasPrePage = pageInfo.isHasPreviousPage();
        this.hasNextPage = pageInfo.isHasNextPage();
        this.navigatepageNums = pageInfo.getNavigatepageNums();
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("Page{");
        sb.append("prePage=").append(prePage);
        sb.append(", currentPage=").append(currentPage);
        sb.append(", nextPage=").append(nextPage);
        sb.append(", totalPage=").append(totalPage);
        sb.append(", isFirstPage=").append(isFirstPage);
        sb.append(", isLastPage=").append(isLastPage);
        sb.append(", hasPrePage=").append(hasPrePage);
        sb.append(", hasNextPage=").append(hasNextPage);
        sb.append(", navigatepageNums=").append(Arrays.toString(navigatepageNums));
        sb.append('}');
        return sb.toString();
    }

    public Integer getPrePage() {
        return prePage;
    }

    public void setPrePage(Integer prePage) {
        this.prePage = prePage;
    }

    public Integer getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(Integer currentPage) {
        this.currentPage = currentPage;
    }

    public Integer getNextPage() {
        return nextPage;
    }

    public void setNextPage(Integer nextPage) {
        this.nextPage = nextPage;
    }

    public Integer getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(Integer totalPage) {
        this.totalPage = totalPage;
    }

    public boolean isFirstPage() {
        return isFirstPage;
    }

    public void setIsFirstPage(boolean isFirstPage) {
        this.isFirstPage = isFirstPage;
    }

    public boolean isLastPage() {
        return isLastPage;
    }

    public void setIsLastPage(boolean isLastPage) {
        this.isLastPage = isLastPage;
    }

    public boolean isHasPrePage() {
        return hasPrePage;
    }

    public void setHasPrePage(boolean hasPrePage) {
        this.hasPrePage = hasPrePage;
    }

    public boolean isHasNextPage() {
        return hasNextPage;
    }

    public void setHasNextPage(boolean hasNextPage) {
        this.hasNextPage = hasNextPage;
    }

    public int[] getNavigatepageNums() {
        return navigatepageNums;
    }

    public void setNavigatepageNums(int[] navigatepageNums) {
        this.navigatepageNums = navigatepageNums;
    }
}
